﻿using System;
using normalize = KeyWordSearch.Normalization;

namespace KeyWordSearch.ProcessTree
{
	internal sealed class OperatorNotProcess:NonTerminalNode
	{
		public OperatorNotProcess(NonTerminalNode parent)
			: base(parent)
		{
			if (parent == null)
			{
				throw new ArgumentNullException("parent");
			}
		}


		public override ExecuteResult Execute(normalize::LiveProgramNormalizationResult inspectionTarget)
		{
			if (Childes.Count != 1)
			{
				throw new ProcessInconsistencyException("子ノードが１個以上存在しているか又は０個です");
			}

			Childes.Reset();
			Childes.Next();

			var ans = Childes.Current.Execute(inspectionTarget);
			ans.Answer = !ans.Answer;

			for (int i = 0; i < ans.ResultElements.Count; i++)
			{
				ans.ResultElements[i].ReportCause = !ans.ResultElements[i].ReportCause;
			}

			return ans;
		}
	}
}
